package com.guofen.controller.cylj;

import com.guofen.pojo.KitchenwasteExport;
import com.guofen.service.cylj.KitchenwasteExportService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api("厨余垃圾黑水虻就地处理站外销记录表")
public class KitchenwasteExportController {
    @Resource
    private KitchenwasteExportService kitchenwasteExportService;

    @ApiOperation("提交厨余垃圾黑水虻就地处理站外销记录")
    @PostMapping("/kitchenwaste/export/add")
    public boolean submitAllInfo(@RequestParam("exportDate") String exportDate, @RequestParam("insectExportWeight") String insectExportWeightstr,@RequestParam("insectDungExportWeight") String insectDungExportWeightstr,
                                 @RequestParam("companyName") String companyName,@RequestParam("contacter") String contacter,@RequestParam("telephone") String telephone,
                                 @RequestParam("yongfa") String yongfa,@RequestParam("feedback") String feedback,@RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        Double insectExportWeight = Double.parseDouble(insectExportWeightstr);
        Double insectDungExportWeight = Double.parseDouble(insectDungExportWeightstr);
        return kitchenwasteExportService.submitAllInfo(new KitchenwasteExport(exportDate,insectExportWeight,insectDungExportWeight,companyName,contacter,telephone,yongfa,feedback,recorder,remark));
    }
    @ApiOperation("获取 当日 最新 一条记录")
    @GetMapping(value = "/kitchenwaste/export/getlast")
    public Result getlast(){
        return  ResultGenerator.genSuccessResult(kitchenwasteExportService.getlast());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/kitchenwaste/export/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(kitchenwasteExportService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/kitchenwaste/export/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "exportDate", value = "日期", required = true) @RequestParam String exportDate,
                         @ApiParam(name = "insectExportWeight", value = "成虫外销重量（kg)", required = true) @RequestParam String insectExportWeightstr,
                         @ApiParam(name = "insectDungExportWeight", value = "虫粪外销重量（kg)", required = true) @RequestParam String insectDungExportWeightstr,
                         @ApiParam(name = "companyName", value = "公司名称", required = true) @RequestParam String companyName,
                         @ApiParam(name = "contacter", value = "联系人", required = true) @RequestParam String contacter,
                         @ApiParam(name = "telephone", value = "联系电话", required = true) @RequestParam String telephone,
                         @ApiParam(name = "yongfa", value = "用途", required = false) @RequestParam String yongfa,
                         @ApiParam(name = "feedback", value = "效果反馈", required = false) @RequestParam String feedback,
                         @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks) {
        Double insectExportWeight = Double.parseDouble(insectExportWeightstr);
        Double insectDungExportWeight = Double.parseDouble(insectDungExportWeightstr);

        return ResultGenerator.genSuccessResult(kitchenwasteExportService.update(new KitchenwasteExport(id,exportDate,insectExportWeight,insectDungExportWeight,
                companyName,contacter,telephone,yongfa,feedback,null,remarks)));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/kitchenwaste/export/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(kitchenwasteExportService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(kitchenwasteExportService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
